package com.spa.domain.service;

import cn.hutool.core.collection.CollectionUtil;
import com.spa.domain.entity.WithdrawAccount;
import com.spa.infrastructure.mapper.WithdrawAccountMapperStruct;
import com.spa.infrastructure.repository.condition.WithdrawAccountCondition;
import com.spa.infrastructure.repository.service.WithdrawAccountRepositoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WithdrawAccountService {
    @Resource
    private WithdrawAccountRepositoryService withdrawAccountRepositoryService;

    /**
     * 匹配技师或门店的账户姓名和账户号，如果存在则更新，不存在就新增
     * @param withdrawAccount
     */
    public void upsertWithdrawAccount(WithdrawAccount withdrawAccount) {
        withdrawAccountRepositoryService.upsert(WithdrawAccountMapperStruct.INSTANCE.entity2Po(withdrawAccount));
    }

    /**
     * 获取最新门店提现账户
     * @param condition
     * @return
     */
    public WithdrawAccount getWithdrawAccountPOLast(WithdrawAccountCondition condition) {
        List<WithdrawAccount> list = WithdrawAccountMapperStruct.INSTANCE.po2Entity4List(withdrawAccountRepositoryService.getWithdrawAccountPOLast(condition));
        WithdrawAccount withdrawAccount = null;
        if (CollectionUtil.isNotEmpty(list)){
            withdrawAccount = list.get(0);
        }
        return withdrawAccount;
    }
}
